package com.core.family.gen.service.gen.Impl.mysql;

import com.core.common.utils.SqlColumnConvertUtil;
import com.core.family.gen.domain.po.TableBeanPo;
import com.core.family.gen.domain.po.TableColumnPo;
import com.core.family.gen.service.gen.Impl.AbsGenHandler;
import com.core.family.gen.service.gen.Impl.mysql.mapper.GeneratorMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 通过 直接查询数据库系统信息表实现 （仅适用mysql）
 */


public class GenMysqlService extends AbsGenHandler {
    @Autowired
    GeneratorMapper generatorMapper;

    @Override
    public List<TableBeanPo> tablesList() {
        List<TableBeanPo> list = generatorMapper.list();
        for (TableBeanPo tableBean : list) {
            tableBean.setClassName(tableToJava(tableBean.getTableName(), ""));
        }
        return list;
    }

    @Override
    public List<TableColumnPo> getColumns(String table) throws Exception {
        List<TableColumnPo> list = generatorMapper.listColumns(table);
        for (TableColumnPo columnBean : list) {
            String str = SqlColumnConvertUtil.convertToAttributeType(columnBean.getColumnName());
            columnBean.setAttrname(str);
        }
        return list;
    }

}
